// guide.js
Page({
  data: {
    // 页面数据
    date: '2025/8/24',
    timestamp: '22:45',
    watermark: '@UI设计',
    navHeight: 142, // 默认导航栏高度 + 10rpx额外间距
    currentIndex: 0, // 当前显示的明信片索引
    isFlipping: false, // 是否正在翻页
    postcardImages: [
      '/images/景点-1.jpg',
      '/images/景点-2.jpg', 
      '/images/景点-3.jpg',
      '/images/景点-4.jpg'
    ],
    postcardTitles: [
      '黑麋峰日出',
      '山间小径',
      '观景台风光',
      '夕阳西下'
    ],
    // 明信片元素开关
    useHandwrittenTitle: true,
    useStamp: true,
    usePaperTexture: true,
    useCornerFold: true,

    // 瀑布流攻略数据
    strategyCards: [
      {
        id: 1,
        username: '山野行者',
        fansCount: 2372,
        avatar: '/images/攻略照片1.jpg',
        title: '黑麋峰日出观赏完全攻略',
        subtitle: '最佳观赏时间和路线指南',
        time: '1-2天',
        difficulty: '中等',
        cost: '200-500元',
        backgroundImage: '/images/攻略照片1.jpg',
        tags: ['日出', '徒步', '摄影'],
        likeCount: 156,
        publishTime: '2小时前'
      },
      {
        id: 2,
        username: '湖南旅游达人',
        fansCount: 3128,
        avatar: '/images/攻略照片2.jpg',
        title: '黑麋峰森林徒步路线详解',
        subtitle: '深度体验原始森林风光',
        time: '半天',
        difficulty: '入门',
        cost: '50-150元',
        backgroundImage: '/images/攻略照片2.jpg',
        tags: ['森林', '徒步', '自然'],
        likeCount: 89,
        publishTime: '5小时前'
      },
      {
        id: 3,
        username: '摄影师小林',
        fansCount: 1895,
        avatar: '/images/攻略照片3.jpg',
        title: '黑麋峰摄影点位大全',
        subtitle: '网红打卡点和拍照技巧',
        time: '2-3小时',
        difficulty: '休闲',
        cost: '免费',
        backgroundImage: '/images/攻略照片3.jpg',
        tags: ['摄影', '打卡', '风景'],
        likeCount: 234,
        publishTime: '1天前'
      },
      {
        id: 4,
        username: '户外探险团',
        fansCount: 1567,
        avatar: '/images/攻略照片4.jpg',
        title: '黑麋峰野餐露营全攻略',
        subtitle: '与大自然亲密接触的完美体验',
        time: '1-2天',
        difficulty: '中等',
        cost: '300-800元',
        backgroundImage: '/images/攻略照片4.jpg',
        tags: ['露营', '野餐', '户外'],
        likeCount: 67,
        publishTime: '3天前'
      }
    ]
  },

  onLoad(options) {
    // 页面加载时的初始化逻辑
    console.log('攻略页面加载完成')
    this.startAutoFlip()
  },

  onShow() {
    // 页面显示时的逻辑
    console.log('攻略页面显示')
    this.startAutoFlip()
  },

  onHide() {
    // 页面隐藏时停止自动切换
    this.stopAutoFlip()
  },

  onUnload() {
    // 页面卸载时清理定时器
    this.stopAutoFlip()
  },

  // 开始自动翻页
  startAutoFlip() {
    this.stopAutoFlip() // 先停止之前的定时器
    this.autoFlipTimer = setInterval(() => {
      this.flipToNext()
    }, 3000) // 每3秒切换一次
  },

  // 停止自动翻页
  stopAutoFlip() {
    if (this.autoFlipTimer) {
      clearInterval(this.autoFlipTimer)
      this.autoFlipTimer = null
    }
  },

  // 切换到下一张明信片
  flipToNext() {
    if (this.data.isFlipping) return // 如果正在切换，则跳过

    const currentIndex = this.data.currentIndex
    const nextIndex = (currentIndex + 1) % this.data.postcardImages.length

    this.setData({
      isFlipping: true
    })

    // 简单的延迟切换内容
    setTimeout(() => {
      this.setData({
        currentIndex: nextIndex,
        isFlipping: false
      })
    }, 300) // 简化切换时间
  },

  // 手动切换到指定明信片
  flipToIndex(index) {
    if (this.data.isFlipping || index === this.data.currentIndex) return

    this.setData({
      isFlipping: true
    })

    // 简单的延迟切换内容
    setTimeout(() => {
      this.setData({
        currentIndex: index,
        isFlipping: false
      })
    }, 300)
  },

  // 导航栏返回按钮点击事件
  onNavBackTap() {
    console.log('导航栏返回按钮点击')
    this.stopAutoFlip() // 停止自动切换
    // 自定义返回逻辑 - 返回到上一页
    wx.navigateBack({
      delta: 1,
      success: () => {
        console.log('成功返回上一页')
      },
      fail: (err) => {
        console.error('返回失败:', err)
        // 如果返回失败，跳转到主页
        wx.redirectTo({
          url: '/pages/index/index'
        })
      }
    })
  },

  // 导航栏高度变化事件
  onNavHeightChange(e) {
    const { totalHeight } = e.detail
    console.log('导航栏高度变化:', totalHeight)
    // 加上额外的10rpx间距
    const adjustedHeight = totalHeight + 10
    this.setData({
      navHeight: adjustedHeight
    })
  },

  // 瀑布流相关方法（已精简：移除关注/点赞/播放/菜单等交互）

  // 点击攻略卡片
  onStrategyCardTap(e) {
    const cardId = e.currentTarget.dataset.id
    const card = this.data.strategyCards.find(c => c.id === cardId)
    
    console.log('点击攻略卡片:', cardId, card.title)
    
    // 跳转到攻略详情页面
    wx.navigateTo({
      url: `/pages/strategy-detail/strategy-detail?id=${cardId}`,
      success: () => {
        console.log('成功跳转到攻略详情页面')
      },
      fail: (err) => {
        console.error('跳转失败:', err)
        wx.showToast({
          title: '页面跳转失败',
          icon: 'none'
        })
      }
    })
  },

  // 点击明信片区域
  onPostcardTap(e) {
    const currentPostcard = this.data.postcardImages[this.data.currentIndex]
    const currentTitle = this.data.postcardTitles[this.data.currentIndex]
    
    console.log('点击明信片:', currentTitle)
    
    // 停止自动切换
    this.stopAutoFlip()
    
    // 跳转到景点详情页面，传递当前明信片的信息
    wx.navigateTo({
      url: `/pages/scenic-detail-view/scenic-detail-view?image=${encodeURIComponent(currentPostcard)}&title=${encodeURIComponent(currentTitle)}&index=${this.data.currentIndex}`
    })
  },

  
}) 